<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
  <% include("/include/header3.html",{"title":"开发-登录日志"}){} %>
</head>
<body>
<div id="app" class="layui-fluid">

  <div class="layui-card">
    <div class="layui-card-body">
      <t-form :data="queryForm" layout="inline" colon>
        <t-form-item label="登录类型">
          <t-input v-model="queryForm.typeLike" placeholder="输入登录类型" clearable></t-input>
        </t-form-item>
        <t-form-item label="登录名称">
          <t-input v-model="queryForm.accountLike" placeholder="输入登录名称" clearable></t-input>
        </t-form-item>
        <t-form-item label="状态">
          <t-select v-model="queryForm.status" :options="statusOptions" placeholder="选择用户状态" clearable></t-select>
        </t-form-item>
        <template v-if="advanced">
          <t-form-item label="开始登录时间">
            <t-date-picker v-model="queryForm.startTime" enable-time-picker placeholder="输入登录开始时间" clearable></t-date-picker>
          </t-form-item>
          <t-form-item label="结束登录时间">
            <t-date-picker v-model="queryForm.endTime" enable-time-picker placeholder="输入登录结束时间" clearable></t-date-picker>
          </t-form-item>
        </template>
        <t-space align="center" breakLine>
          <t-button theme="primary" @click="queryData">
            <template #icon><i class="layui-icon layui-icon-search text-size-14 mr-10"></i></template>
            查询
          </t-button>
          <t-link theme="primary" @click="advanced=!advanced"><i class="layui-icon" :class="'layui-icon-'+(advanced ? 'up': 'down')"></i> {{advanced?'关闭':'展开'}}</t-link>
        </t-space>
      </t-form>
    </div>
  </div>

  <div class="layui-card">
    <div class="layui-card-body">
      <t-table :columns="columns" :data="table.data" :loading="table.loading" bordered hover resizable>
        <template #loading>
          <div class="t-table--loading-message">加载数据中，请稍后...</div>
        </template>
      </t-table>
      <div class="pa-25 pb-15">
        <t-pagination v-model="queryForm.pageNumber" v-model:page-size="queryForm.pageSize" :total="table.totalRow" show-first-and-last-page-btn show-jumper
                      @change="queryData"></t-pagination>
      </div>
    </div>
  </div>
</div>

<script>
  const PATH_URL = "dev/loginLog/";
</script>
<script>

  setupVue("#app", {
    setup() {

      const advanced = Vue.ref(false);

      // 查询表单
      const queryForm = Vue.reactive({ pageNumber: 1, pageSize: 10 });
      // 表格相关
      const table = useTable();
      const fetchData = window.reloadData = () => fetchPage(axiosGet, PATH_URL + "page", queryForm, table);
      const queryData = (info = {}) => {
        const { current = 1, pageSize } = info;
        queryForm.pageNumber = current;
        if (pageSize) queryForm.pageSize = pageSize;
        fetchData();
      }
      init(() => {
        fetchData();
      });

      // 打开编辑窗口
      const onDetail = (row) => {
        openLayer({
          title: '查看【' + row.account + '】登录日志',
          content: PATH_URL + "detail",
          data: { id: row.id },
        });
      }

      // 删除
      const clickDelete = (row) => handleDelete(axiosDelete, PATH_URL + "delete", { id: row.id }, table, "确定删除【" + row.account + "】登录日志吗？", fetchData);
      // 状态选项
      const statusOptions = [{ label: "全部", value: "" }, { label: "登录成功", value: 1, theme: "success" }, { label: "登录失败", value: 0, theme: "danger" }];


      // 表格列表显示
      const columns = [
        { colKey: 'serial-number', align: 'center', title: '序', width: "40px" },
        { colKey: 'type', title: '登录类型', align: 'center', width: '120px' },
        { colKey: 'userId', title: '用户标识', align: 'center', width: '140px' },
        { colKey: 'account', title: '登录名称', align: 'center', width: '150px', ellipsis: true },
        {
          colKey: 'status', title: '状态', align: 'center', width: '100px', cell: (h, { row }) => {
            const status = statusOptions.find(item => item.value === row.status);
            if (status) {
              return h(TDesign.Tag, { variant: 'light-outline', theme: status.theme }, status.label)
            } else {
              return h(TDesign.Tag, { variant: 'light-outline', theme: 'danger' }, '未知状态')
            }
          },
        },
        { colKey: 'msg', title: '登录描述', align: 'center', width: '180px', ellipsis: true },
        { colKey: 'time', title: '登录时间', align: 'center', width: '140px' },
        { colKey: 'ipAddress', title: '登录地址', align: 'center', width: '140px', ellipsis: true },
        {
          title: '操作',
          align: 'center', width: '150px',
          cell: (h, { row }) => {
            return h(TDesign.Space, {}, [
              h(TDesign.Button, { theme: 'primary', onClick: () => onDetail(row) }, '查看'),
              h(TDesign.Button, { theme: 'danger', onClick: () => clickDelete(row) }, '删除'),
            ]);
          },
        },
      ];

      return {
        queryForm, advanced,
        table, columns, queryData,
        statusOptions,
      }
    },
  });
</script>


</body>
</html>
